package com.jobchecks.common.exception;


import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
 * 基础异常
 *
 * @author huangjinjia
 */
@SuppressWarnings("all")
@Setter
@Getter
public class BaseException extends RuntimeException implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 异常编码
     */
    public Integer code;

    /**
     * 错误消息
     */
    public String msg;

    public BaseException() {
    }

    public BaseException(String msg) {
        super(msg);
        this.code = BaseExceptionCode.SYS_ERROR.getCode();
        this.msg = msg;
    }

    public BaseException(Integer code, String msg) {
        super(new StringBuilder("异常码：").append(code).append("  异常描述：").append(msg).toString());
        this.code = code;
        this.msg = msg;
    }

    public BaseException(BaseExceptionCode exceptionCode) {
        super(new StringBuilder("异常码：").append(exceptionCode.getCode()).append("  异常描述：").append(exceptionCode.getDesc()).toString());
        this.code = exceptionCode.getCode();
        this.msg = exceptionCode.getDesc();
    }

    public BaseException(String msg, Throwable cause) {
        super(msg, cause);
        this.msg = msg;
        this.code = BaseExceptionCode.SYS_ERROR.getCode();
    }

    public BaseException(Integer code, String msg, Throwable cause) {
        super(msg, cause);
        this.msg = msg;
        this.code = code;
    }

    public BaseException(Integer code, String msg, String exceptionMsg) {
        super(msg);
        this.msg = msg;
        this.code = code;
    }
}
